<?php
	class news_commentControl extends skymvc{
		
		public function __construct(){
			parent::__construct();
		}
		
		public function onDefault(){
			
		}
		
		public function onSave(){
			M("login")->checklogin();
			$userid=M("login")->userid;
			M("news_blacklist")->check($userid);
			$data=M("news_comment")->postData();
			$news=M("news")->selectRow("newsid=".$data['newsid']);
			if(!$news){
				$this->goAll("数据出错",1);
			}
			$data['siteid']=SITEID;			
			$data['userid']=$userid;
			$data['dateline']=time();
			$id=M("news_comment")->insert($data);
			M("news")->changenum("comment_num",1,"newsid=".$data['newsid']);
			//通知作者
			if($news['userid']!=$userid){
				M("notice")->add(array(
					"userid"=>$news['userid'],
					"content"=>"【评论】".$data['content']
				));
			}
			
			$this->goAll("评论成功",0,array("id"=>$id));
		}
		
		public function onDelete(){
			M("login")->checklogin();
			$id=get('id','i');
			$row=M("news_comment")->selectRow("id=".$id);
			$userid=M("login")->userid;
			$news=M("news")->selectRow("newsid=".$row['newsid']);
			if($row['userid']!=$userid && $news['userid']!=$userid){
				$this->goAll("暂无权限",1);
			}else{
				M("news")->changenum("comment_num",-1,"newsid=".$news['newsid']);
				M("news_comment")->delete("id=".$id);
					$this->goAll("删除成功");
			}
		}
		
	}
?>